Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max_flow_rate to LinearResistance #1100

Merged
merged 3 commits into from
Feb 9, 2024
Merged

Add max_flow_rate to LinearResistance #1100

merged 3 commits into from
Feb 9, 2024

Conversation

visr
Copy link
Member

@visr visr commented Feb 8, 2024

This is needed to be able to model structures that exchange flow based on a water level difference, but only up to a certain capacity.

Ref Deltares/Ribasim-NL#62

The updated test model now looks like this:

image

@visr visr added physics Physical process representation concept labels Feb 8, 2024
@visr visr requested a review from SouthEndMusic February 8, 2024 16:39
Comment on lines 34 to 36
# TODO adapt for max_flow_rate of 6e-5
storage_analytic =
@. limit_storage + (storage[1] - limit_storage) * exp.(decay_rate * t)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SouthEndMusic it would be great if you could help updating this test value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solve for Q(level) == max_flow_rate

Find out at which times it switches from max_flow_rate to dynamic flow rate

Compute from there

@SouthEndMusic
Copy link
Collaborator

SouthEndMusic commented Feb 8, 2024

DE for $u(t)$:

$$ u'(t) = \text{clamp}\left(\frac{L - \frac{u(t)}{A}}{R}, -q_{\max}, q_{\max}\right), \quad R, A, q_{\max} > 0. $$

For simplicity we assume a constant area here, which is not the case in the current linear resistance test model but is now supported.

Initial condition:

$$ u(0) = u_0 > 0. $$

We assume $u_0$ is big enough such that

$$ \frac{L - \frac{u_0}{A}}{R} < -q_{\max}. $$

Hence for $0 &lt; t &lt; t_\text{shift}$ we have that

$$ u(t) = u_0 - q_{\max} t. $$

$t_\text{shift}$ is given by

$$ \frac{L - \frac{u(t_\text{shift})}{A}}{R} = -q_{\max}. $$

Substituting the above expression for $u(t)$ yields

$$ t_\text{shift} = \frac{u_0 - A(L + Rq_{\max})}{ q_{\max}}, $$

and so

$$ u(t_\text{shift}) = A(L + Rq_{\max}). $$

Now we solve from here with

$$ u'(t) = \frac{L - \frac{u(t)}{A}}{R}, $$

which yields

$$ AL = ARu'(t) + u(t) = AR \exp\left(-\frac{t}{AR}\right)\left[u(t)\exp\left(\frac{t}{AR}\right)\right]' $$

and so

$$ u(t)\exp\left(\frac{t}{AR}\right) = \frac{L}{R}\int \exp\left(\frac{t}{AR}\right) \text{d} t = AL \exp\left(\frac{t}{AR}\right) + C, $$

which gives

$$ u(t) = AL + C \exp\left(-\frac{t}{AR}\right). $$

This makes sense; $u(t)$ will converge to $AL$, the volume in the basin at the level of the level boundary.

Filling in our initial condition:

$$ u(t_\text{shift}) = AL + C \exp\left(-\frac{t_\text{shift}}{AR}\right) = A(L + Rq_{\max}) $$

yields

$$ C = ARq_{\max} \exp\left(\frac{t_\text{shift}}{AR}\right). $$

We conclude:

$$ u(t) = \begin{cases} u_0 - q_{\max} t \quad \text{if} \quad 0 \leq t \leq t_\text{shift}, \\ AL + ARq_{\max} \exp\left(-\frac{t - t_\text{shift}}{AR}\right) \quad \text{if} \quad t > t_\text{shift} \end{cases} $$

and

$$ u'(t) = \begin{cases} - q_{\max}\quad \text{if} \quad 0 \leq t \leq t_\text{shift}, \\ -q_{\max} \exp\left(-\frac{t - t_\text{shift}}{AR}\right) \quad \text{if} \quad t > t_\text{shift} \end{cases}, $$

where

$$ t_\text{shift} = \frac{u_0 - A(L + Rq_{\max})}{ q_{\max}}. $$

Copy link
Collaborator

@SouthEndMusic SouthEndMusic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, I trust you can update the analytical test with the maximum flow 👍

core/src/solve.jl Outdated Show resolved Hide resolved
docs/core/equations.qmd Outdated Show resolved Hide resolved
@visr visr force-pushed the max_flow_rate branch 2 times, most recently from 4a468de to ae9d128 Compare February 9, 2024 15:59
@visr
Copy link
Member Author

visr commented Feb 9, 2024

image

The storage in black nicely goes from your u pre-shift in green to u post-shift in blue.

@visr visr merged commit 3565646 into main Feb 9, 2024
21 checks passed
@visr visr deleted the max_flow_rate branch February 9, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physics Physical process representation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants